package com.bootdo.clouddo.service.douban.impl;

import com.bootdo.clouddo.dao.douban.DbBookRecommendationMapper;
import com.bootdo.clouddo.domain.douban.DbBookRecommendation;
import com.bootdo.clouddo.service.douban.IDbBookRecommendationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DbBookRecommendationServiceImpl implements IDbBookRecommendationService {

    @Autowired
    private DbBookRecommendationMapper dao;

    @Override
    public List<DbBookRecommendation> findBySubjectId(Long subjectId) {
        return dao.findBySubjectId(subjectId);
    }

    @Override
    public List<Long> findNoRecommendIds() {
        return dao.findNoRecommendIds();
    }

    @Override
    public Boolean exists(Long sid, Long subjectId) {
        return dao.exists(sid, subjectId);
    }

    @Override
    public int save(DbBookRecommendation record) {
        if(record.getSid() == null || record.getSubjectId() == null)
            return 0;
        if(dao.exists(record.getSid(), record.getSubjectId()))
            return 0;
        return dao.insertSelective(record);
    }
}
